# 作者: YYJ
# 2025年06月27日18时35分46秒
# 2486249622@qq.com


def my_sort_key(word):
    return word.lower()


class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __repr__(self):
        return "Student(%s, %s)" % (self.name, self.age)


if __name__ == '__main__':

    a = [5,3,8,6,2,9,1,4,7]

    print(sorted(a))

    print(sorted({'xiaoming' : 18, 'xiaohong' : 16, 'xiaohuang' : 19}))
    word_list = "The is a test string from Andrew".split()
    print(sorted(word_list))
    print(sorted(word_list, key = my_sort_key)) # 按照自己的规则排序

    print("-" * 20)
    stu_tuples = [(20, 'xiaoming'), (18, 'xiaohong'), (19, 'xiaohuang')]
    print(sorted(stu_tuples, key = lambda x: x[1], reverse = True)) # 按照名字排序
    from operator import itemgetter, attrgetter
    print(sorted(stu_tuples, key = itemgetter(1), reverse = True))
    print("-" * 20)
    stu_objects = [Student('xiaoming', 20), Student('xiaohong', 18), Student('xiaohuang', 19)]
    print(sorted(stu_objects, key = lambda x: x.age))
    print(sorted(stu_objects, key = attrgetter('age')))
    print("多级排序")
    print(sorted(stu_objects, key = lambda x: (x.age, x.name)))
    print("字典混合list")
    mydict = {'xiaoming': [20, 170], 'xiaohong': [18, 160], 'xiaohuang': [19, 180]}
    print(sorted(mydict.items(), key = lambda x: x[1][0]))